package cn.edu.neusoft.wuguangsheng.flowerimpression.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import cn.edu.neusoft.wuguangsheng.flowerimpression.CircleImageView;
import cn.edu.neusoft.wuguangsheng.flowerimpression.R;
import cn.edu.neusoft.wuguangsheng.flowerimpression.activity.OrderViewActivity;
import cn.edu.neusoft.wuguangsheng.flowerimpression.activity.ShopMyCommentActivity;
import cn.edu.neusoft.wuguangsheng.flowerimpression.activity.UserAddressListActivity;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.UserInfoBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.listener.TListener;
import cn.edu.neusoft.wuguangsheng.flowerimpression.model.UserInfoModel;
import cn.edu.neusoft.wuguangsheng.flowerimpression.service.Service;

/**
 * A simple {@link Fragment} subclass.
 */
public class ShopWodFragment extends BaseFragment implements View.OnClickListener{
    TextView usershop_order;
    LinearLayout usershop_shdz;
    CircleImageView shopwode_userimg;
    TextView shopwode_username;
    TextView shopwode_userphone;
    TextView usershop_mypinglun;


    @Override
    void initView() {
        usershop_order = (TextView)view.findViewById(R.id.usershop_order);
        usershop_shdz = (LinearLayout)view.findViewById(R.id.usershop_shdz);
        usershop_mypinglun = (TextView)view.findViewById(R.id.usershop_mypinglun);

        shopwode_userimg = (CircleImageView)view.findViewById(R.id.shopwode_userimg);
        shopwode_username = (TextView)view.findViewById(R.id.shopwode_username);
        shopwode_userphone = (TextView)view.findViewById(R.id.shopwode_userphone);

        UserInfoModel userInfoModel = new UserInfoModel();
        userInfoModel.getUserInfo(getid(), new TListener<UserInfoBean>() {
            @Override
            public void onResponse(UserInfoBean userInfoBean) {
                String username = userInfoBean.getUser_name();
                String userphone = userInfoBean.getUser_phone();
                //String userphoto = userInfoBean.getUser_photo();
                String sex = userInfoBean.getUser_sex();
                if (userInfoBean.getUser_photo().equals("1") || userInfoBean.getUser_photo().equals("1.jpg")){
                    if (sex.equals("1")){
                        shopwode_userimg.setImageResource(R.mipmap.nanshi);
                    }
                    else{
                        shopwode_userimg.setImageResource(R.mipmap.nvshi);
                    }
                }
                else{
                    String img = Service.BASE_URL+"flower_impression/public/uploads/"+userInfoBean.getUser_photo();
                    Picasso.with(getContext()).load(img).into(shopwode_userimg);
                }
                shopwode_username.setText(username);
                shopwode_userphone.setText(userphone);
            }

            @Override
            public void onFail(String msg) {

            }
        });

    }

    @Override
    void initEvent() {
        usershop_order.setOnClickListener(this);
        usershop_shdz.setOnClickListener(this);
        usershop_mypinglun.setOnClickListener(this);
        shopwode_userimg.setOnClickListener(this);

    }

    @Override
    void initDate() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.usershop_order:
                Intent intent = new Intent(getContext(), OrderViewActivity.class);
                startActivity(intent);
                break;
            case R.id.usershop_shdz:
                Intent intent1 = new Intent(getContext(), UserAddressListActivity.class);
                startActivity(intent1);
                break;
            case R.id.usershop_mypinglun:
                Intent intent2 = new Intent(getContext(), ShopMyCommentActivity.class);
                startActivity(intent2);
                break;
            case R.id.shopwode_userimg:
                Toast.makeText(getContext(),"修改头像请退出到花印象平台个人主页修改",Toast.LENGTH_SHORT).show();
                break;
        }

    }

    public ShopWodFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        setLayout_file(R.layout.fragment_shop_wod);
        return super.onCreateView(inflater,container,savedInstanceState);
    }

}
